package com.yylc.cscore.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.yylc.cscore.bean.TaskTypeBean;
import com.yylc.cscore.dao.TaskTypeDao;
import com.yylc.cscore.entity.TaskTypeEntity;
import com.yylc.cscore.service.TaskTypeService;
import com.yylc.cscore.util.R;
import com.yylc.cscore.util.YYlcBeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xiangnan
 * date 2018/5/3
 */
@Service
public class TaskTypeServiceImpl implements TaskTypeService {

    @Resource
    private TaskTypeDao taskTypeDao;

    @Override
    public List<TaskTypeBean> getTaskTypeList() {
        List<TaskTypeBean> beanList = new ArrayList<>();
        List<TaskTypeEntity> entityList = taskTypeDao.selectList();
        entityList.forEach(entity -> beanList.add(YYlcBeanUtils.copyProperties(entity, new TaskTypeBean())));

        return beanList;
    }

    @Override
    public List<TaskTypeBean> getTaskTypeList(String typeCodes) {
        List<TaskTypeBean> beanList = new ArrayList<>();
        List<String> idList = CollectionUtil.newArrayList(StrUtil.split(typeCodes, R.partFlag));
        idList.forEach(id -> {
            TaskTypeEntity entity = taskTypeDao.select(id);
            beanList.add(entity != null ? YYlcBeanUtils.copyProperties(entity, new TaskTypeBean()) : new TaskTypeBean());
        });

        return beanList;
    }

}
